package com.mgvlife.ddlw.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.mgvlife.ddlw.formbean.ClazzForm;
import com.mgvlife.ddlw.service.ClazzService;
import com.mgvlife.ddlw.vo.Result;
import com.mgvlife.ddlw.vo.VoClazz;
import com.mgvlife.ddlw.vo.VoClazz2;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xinhuo.util.JsonUtil;
import com.xinhuo.vo.JsonEasyUI;

@Controller("clazzAction")
@Scope("prototype")
public class ClazzAction extends ActionSupport implements
		ModelDriven<ClazzForm> {

	private static final long serialVersionUID = -2705157115539910412L;
	private ClazzForm dataForm = new ClazzForm();
	@Resource
	private ClazzService clazzService = null;

	public void add() {
		Result result = null;
		try {
			result = clazzService.clazzAdd(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void update() {
		Result result = null;
		try {
			result = clazzService.clazzUpdate(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void list() {
		JsonEasyUI<VoClazz> result = null;
		try {
			result = clazzService.getData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}
	
	public void listAll() {
		JsonEasyUI<VoClazz2> result = null;
		try {
			result = clazzService.getAllData();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void delete() {
		Result result = null;
		try {
			result = clazzService.clazzDelete(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	@Override
	public ClazzForm getModel() {
		return dataForm;
	}

}
